<template>
  <div>
    <div class="system-user-search mb15">
				<el-input size="default" placeholder="请输入患者名称或id" v-model="nameandid" style="max-width: 180px"> </el-input>
				<el-button size="default" type="primary" @click="listByname()" class="ml10">
					<el-icon>
						<ele-Search />
					</el-icon>
					查询
				</el-button>
				<el-button size="default" type="success" @click="onOpenAddPati()" class="ml10">
					<el-icon>
						<ele-FolderAdd />
					</el-icon>
					新增患者
				</el-button>
			</div>
      <el-table
    :data="pagination.records"
    border 
    style="width: 100%">
    <el-table-column  fixed prop="ptCard"  label="病人编号"   width="150"></el-table-column>
    <el-table-column fixed prop="ptName" label="病人姓名"    width="120"> </el-table-column>
    <el-table-column  prop="ptGender" label="病人性别"    width="120"> </el-table-column>
    <el-table-column   prop="ptAge" label="病人年龄"   width="120"> </el-table-column>
    <el-table-column  prop="ptPhone"  label="病人电话"   width="300">  </el-table-column>
    <el-table-column prop="registerType.rtName" label="挂号类型ID" width="120"> </el-table-column>
	  <el-table-column  prop="registerCost.rcName"  label="挂号费ID"   width="120"></el-table-column>
    <el-table-column prop="departmentClass.dpcName" label="科室ID"    width="120"> </el-table-column>
    <el-table-column   prop="tsId" label="就诊状态ID"   width="120"> </el-table-column>
    <el-table-column  prop="ptCreateTime"  label="创建时间"   width="300">  </el-table-column>
    <el-table-column prop="sysUser.userName" label="所属医师ID" width="120"> </el-table-column>
    <el-table-column fixed="right"  label="操作" width="100">
      <template slot-scope="scope">
     <el-button @click="del(scope.row)"  type="text" size="small">删除</el-button>
    <el-button type="text" size="small" @click="upPatiUI(scope.row)">编辑</el-button>
      </template>
    </el-table-column>
  </el-table>
  <div class="block">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :hide-on-single-page="true"
      :current-page="pagination.current"
		  :page-sizes="[3,5,8,10]"
		  :page-size="pagination.size"
		  layout="total,sizes, prev, pager, next, jumper"
		  :total="pagination.total">
    </el-pagination>
  </div>
    <!-- <el-button @click="list()"  >测速</el-button> -->
    <el-dialog title="添加患者" :visible.sync="addTag" :close-on-click-modal="false">
			  <el-form :model="ruleForm" size="small" label-width="90px">
				<el-row :gutter="35">
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="患者名称">
							<el-input v-model="ruleForm.ptName" placeholder="请输入患者名称" clearable></el-input>
						</el-form-item>
					</el-col>


          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="年龄">
							<el-input   v-model="ruleForm.ptAge" placeholder="请输入用户年龄" clearable></el-input>
						</el-form-item>
					</el-col>

           <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="手机号">
							<el-input v-model="ruleForm.ptPhone" placeholder="请输入手机号" clearable></el-input>
						</el-form-item>
					</el-col>

					
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="挂号类型">
							<el-select v-model="ruleForm.rtId" placeholder="请选择" style="width:100%">
            <el-option
             v-for="item in registerTypeData"
              :key="item.rtId"
              :label="item.rtName"
              :value="item.rtId">
            </el-option>
           </el-select>
						</el-form-item>
					</el-col>
          
          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="挂号级别">
								<el-select v-model="ruleForm.rcId" placeholder="请选择" style="width:100%">
            <el-option
             v-for="item in registerCostData"
              :key="item.rcId"
              :label="item.rcName"
              :value="item.rcId">
            </el-option>
           </el-select>
						</el-form-item>
					</el-col>

          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="科室">
							<el-select v-model="ruleForm.dpcId" placeholder="请选择"  style="width:100%"  >
            <el-option
             v-for="item in departmentClassData"
              :key="item.dpcId"
              :label="item.dpcName"
              :value="item.dpcId">
            </el-option>
           </el-select>
						</el-form-item>
					</el-col>
          
          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="性别" prop="sex">
				     <el-radio-group v-model="ruleForm.ptGender">
					    <el-radio label="男">男</el-radio>
					    <el-radio label="女">女</el-radio>
					  </el-radio-group>
				  </el-form-item>
					</el-col>

					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="用户状态">
							<el-switch v-model="ruleForm.status" inline-prompt active-text="启" inactive-text="禁"></el-switch>
						</el-form-item>
					</el-col>
				
				</el-row>
			</el-form>
      <template #footer>
				<span class="dialog-footer">
					<el-button @click="onCancel" size="default">取 消</el-button>
					<el-button type="primary" @click="onSubmit" size="default">新 增</el-button>
				</span>
			</template>
			</el-dialog>


      <el-dialog title="修改患者" :visible.sync="upTag" :close-on-click-modal="false">
			  <el-form :model="patiForm" size="small" label-width="90px">
				<el-row :gutter="35">
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="患者名称">
							<el-input v-model="patiForm.ptName" placeholder="请输入患者名称" clearable></el-input>
						</el-form-item>
					</el-col>


          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="年龄">
							<el-input   v-model="patiForm.ptAge" placeholder="请输入用户年龄" clearable></el-input>
						</el-form-item>
					</el-col>

           <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="手机号">
							<el-input v-model="patiForm.ptPhone" placeholder="请输入手机号" clearable></el-input>
						</el-form-item>
					</el-col>

					
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="挂号类型">
							<el-select v-model="patiForm.rtId" placeholder="请选择" style="width:100%">
            <el-option
             v-for="item in registerTypeData"
              :key="item.rtId"
              :label="item.rtName"
              :value="item.rtId">
            </el-option>
           </el-select>
						</el-form-item>
					</el-col>
          
          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="挂号级别">
								<el-select v-model="patiForm.rcId" placeholder="请选择" style="width:100%">
            <el-option
             v-for="item in registerCostData"
              :key="item.rcId"
              :label="item.rcName"
              :value="item.rcId">
            </el-option>
           </el-select>
						</el-form-item>
					</el-col>

          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="科室">
							<el-select v-model="patiForm.dpcId" placeholder="请选择"  style="width:100%"  >
            <el-option
             v-for="item in departmentClassData"
              :key="item.dpcId"
              :label="item.dpcName"
              :value="item.dpcId">
            </el-option>
           </el-select>
						</el-form-item>
					</el-col>
          
          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="性别" prop="sex">
				     <el-radio-group v-model="patiForm.ptGender">
					    <el-radio label="男">男</el-radio>
					    <el-radio label="女">女</el-radio>
					  </el-radio-group>
				  </el-form-item>
					</el-col>

					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  >
						<el-form-item label="用户状态">
							<el-switch v-model="patiForm.status" inline-prompt active-text="启" inactive-text="禁"></el-switch>
						</el-form-item>
					</el-col>
				
				</el-row>
			</el-form>
      <template #footer>
				<span class="dialog-footer">
					<el-button @click="uponCancel" size="default">取 消</el-button>
					<el-button type="primary" @click="uponSubmit" size="default">修 改</el-button>
				</span>
			</template>
			</el-dialog>
  </div>
</template>

<script>
import pati from '@/api/pati';

export default {
    name: 'patiList',
    methods:{
      //分页
        handleSizeChange(value) {
          this.pagination.size = value
          this.list(this.pagination.current,this.pagination.size);
       },
        handleCurrentChange(value) {
          this.pagination.current = value
          this.list(this.pagination.current,this.pagination.size);
       },
       del(pat){
         this.$confirm('此操作将永久删除名字为'+pat.ptName+'的用户, 是否继续?', '提示', {
                    type: 'warning'
                    }).then(() => {
                        pati.deletepati(pat.ptId).then(resp=>{
                           this.list();
                        })
                      this.$message({type: 'success',message: '删除成功!'});
                     
                    }).catch(() => {
                       this.$message({type: 'info',message: '已取消删除'});          
                    });
       } ,
       upPatiUI(pat){
         pati.upPatiUI(pat.ptId).then(resp=>{
            this.patiForm=resp;
              pati.getListDto().then(resp=>{
              this. registerTypeData=resp.registerTypeList;
              this.registerCostData=resp.registerCostList;
              this.departmentClassData=resp.departmentClassList;
            });
            this.upTag = true;
         })
       },
        list(pageym=1,pagesize=8){
            pati.findPati(pageym,pagesize).then(resp=>{
               this.pagination=resp;
            });
        },
      listByname(pageym=1,pagesize=10) {
           pati.listByname(pageym,pagesize,this.nameandid,this.nameandid).then(resp=>{
               this.pagination=resp;
            });
      },
      // 打开新增用户弹窗
		 onOpenAddPati() {
       pati.getListDto().then(resp=>{
          this. registerTypeData=resp.registerTypeList;
          this.registerCostData=resp.registerCostList;
          this.departmentClassData=resp.departmentClassList;
       })
      this.addTag=true;
    },
    
    	 onCancel () {
         this.addTag = false;
         	this.ruleForm={};
         	
    },
     uponCancel () {
         this.upTag = false;
         this.patiForm={};
    },
     uponSubmit () {
        this.patiForm.wid=this.$store.state.userInfos.userInfos.user.userId
        pati.uppati(this.patiForm).then(resp=>{
          this.$message({type: 'success',message: resp.message});
            		this.upTag=false;
            		this.patiForm={};
            		this.list();
       })
		},
		// 新增
		 onSubmit() {
       this.ruleForm.wid=this.$store.state.userInfos.userInfos.user.userId
       pati.addpati(this.ruleForm).then(resp=>{
        this.$message({type: 'success',message: resp.message});
            		this.addTag=false;
            		this.ruleForm={};
            		this.list();
       })
		}
    },
        data() {
      return {
        pagination:{},//分页对象
        nameandid:"",//查询参数
        addTag:false,//是否显示添加弹窗
        upTag:false,//是否显示修改弹窗
        ruleForm:{},//添加患者的对象
        patiForm:{},//修改患者的对象
        registerTypeData: [], // 挂号类型
        registerCostData: [], // 挂号费用
        departmentClassData: [], // 科室
       
      }
        }
    ,  
    mounted() {
        this.list(1,8);
    },
}
</script>

<style>

</style>